import { IFormProps, size, formItemLayout } from '../../utils/common';
import React from 'react';
import { Modal, Form, Input, Select, Checkbox } from 'antd';
import * as api from '../../api/api';
import { FormComponentProps } from 'antd/lib/form';
export interface IbusinessScopeEditProps extends FormComponentProps {
    visible: boolean,
    businessScope?: api.SingleUserMallItemsVOBusinessScopeVO,
    onSave: (any) => void,
    onCancel: () => void,
}
class businessScopeEdit extends React.PureComponent<IbusinessScopeEditProps, any>{
    constructor(props) {
        super(props);
    }
    ok = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, form) => {
            if (!err) {
                this.props.onSave(form);
            }
        });
    }

    cancel = () => {
        this.props.onCancel();
    }
    render(): JSX.Element {
        const { getFieldDecorator } = this.props.form;
        const { businessScope } = this.props;
        return (
            <Modal
                title='经营范围信息'
                visible={this.props.visible}
                onOk={this.ok}
                onCancel={this.cancel}
                maskClosable={true}
            >
                <Form>
                    <Form.Item {...formItemLayout} >
                        {getFieldDecorator('id', {
                            initialValue: businessScope && businessScope.id
                        })(<Input size={size} type="hidden" />)}
                    </Form.Item>
                    <Form.Item label="经营范围名称" {...formItemLayout}>
                        {getFieldDecorator('name', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入经营范围名称'
                                }
                            ],
                            initialValue: businessScope && businessScope.name
                        })(<Input size={size}
                            placeholder="请输入经营范围名称" />)}
                    </Form.Item>
                    <Form.Item label="是否启用" {...formItemLayout}>
                        {getFieldDecorator('isUse', {
                            valuePropName: 'checked',
                            initialValue: businessScope && businessScope.isUse
                        })(<Checkbox />)}
                    </Form.Item>
                </Form>
            </Modal>)
    }
}

export default Form.create()(businessScopeEdit);